var templateDoc;
(function($) {
    'use strict';

    // Preloader
    $(window).on('load', function() {
        $('.preloader').addClass('hidden');
        $('[data-popup="tooltip"]').tooltip();
    });
    $(".hamburger>.hamburger_btn").on('click', function() {
        $(".header .navigation").toggleClass('open');
        $(this).toggleClass('active');
    });
    // Mobile Menu
    $(".header .menu-item-has-children > a").on('click', function(e) {
        var submenu = $(this).next(".sub-menu");
        e.preventDefault();
        submenu.slideToggle(200);
    });
    // Team Social
    $(".team_share").on('click', function(e) {
        var teamsocial = $(this).next(".team_share + .social");
        e.preventDefault();
        teamsocial.slideToggle(200);
    });

    // Sticky Header
    var header = $(".can-sticky");
    var footer = $(".ft-sticky");
    var headerHeight = header.innerHeight();
    var FooterHeight = footer.innerHeight();

    function doSticky() {
        if (window.pageYOffset > headerHeight) {
            header.addClass("sticky");
        } else {
            header.removeClass("sticky");
        }
        if (window.pageYOffset > FooterHeight) {
            footer.addClass("d-flex");
        } else {
            footer.removeClass("d-flex");
        }
    }
    doSticky();
    //On scroll events
    $(window).on('scroll', function() {
        doSticky();
    });
    if ($(".back-to-top").length) {
        $(".back-to-top").on("click", function() {
            var target = $(this).attr("data-target");
            // animate
            $("html, body").animate({
                    scrollTop: $(target).offset().top,
                },
                1000
            );

            return false;
        });
    };
    $('.thm-btn .button_title').each(function() {
        $(this).html($(this).text().replace(/([^\x00-\x80]|\w)/g, "<span class='btn_letters'>$&</span>"));
    });
    var btnHover = document.querySelectorAll('.thm-btn');
    btnHover.forEach(function(btnHover) {
        btnHover.addEventListener('mouseenter', function() {
            var letter = btnHover.querySelectorAll('.btn_letters');
            anime.timeline({}).add({
                targets: letter,
                translateY: ["1.1em", 0],
                translateZ: 0,
                duration: 750,
                delay: (el, i) => 50 * i
            });
        });
    });
    // Current year
    var d = new Date();
    document.getElementById("year").innerHTML = d.getFullYear();
    // testimonial_slider
    $('.testimonial_slider').slick({
        infinite: true,
        slidesToShow: 1,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        dots: true,
        arrows: false,
        dotsClass: "slick-dots d-flex"
    });
    // service_slider
    $('.service_slider').slick({
        infinite: true,
        slidesToShow: 3,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        dots: true,
        arrows: false,
        dotsClass: "slick-dots d-flex",
        responsive: [{
                breakpoint: 992,
                settings: {
                    slidesToShow: 2
                }
            },
            {
                breakpoint: 768,
                settings: {
                    slidesToShow: 1
                }
            }
        ]
    });
    templateDoc = {
        init: function() {
            this.mainBanner();
        },
        // Main Banner
        mainBanner() {
            var sliderContent = $('.banner_slider'),
                countStatus = $('.slider-count');

            sliderContent.slick({
                infinite: true,
                slidesToShow: 1,
                slidesToScroll: 1,
                autoplay: true,
                autoplaySpeed: 1000,
                speed: 1000,
                dots: true,
                dotsClass: "slick-dots container",
                appendDots: $('.slick-slider-dots'),
                arrows: false
            });

            sliderContent.on('init reInit afterChange', function(
                event,
                slick,
                currentSlide,
                nextSlide
            ) {
                if (!slick.$dots) {
                    return;
                }
                var i = (currentSlide ? currentSlide : 0) + 1;
                var statusText = i > 10 ? i : '0' + i;
                countStatus.html(
                    '<span class="current">' +
                    statusText +
                    '</span>' +
                    '<small>/' + slick.$dots[0].children.length + '</small>'
                );
            });
        },
    };
    $(document).ready(function() {
        templateDoc.init();
    });
})(jQuery);